Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typos + title #568

Merged
merged 1 commit into from
Mar 27, 2024
Merged

typos + title #568

merged 1 commit into from
Mar 27, 2024

Conversation

mruwnik
Copy link
Collaborator

@mruwnik mruwnik commented Mar 23, 2024

No description provided.

Copy link
Collaborator

@jrhender jrhender left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing show stopping but a couple comments

Comment on lines 11 to 25
export const loader = async ({request}: Parameters<LoaderFunction>[0]) => {
const url = new URL(request.url)
const stateFromUrl = url.searchParams.get('state')
if (stateFromUrl) {
const firstOpenId = getStateEntries(stateFromUrl).filter(
([_, state]) => state === QuestionState.OPEN
)[0]?.[0]
if (firstOpenId) {
url.searchParams.delete('state')
url.pathname = questionUrl({pageid: firstOpenId})
throw redirect(url.toString())
}
}
return null
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mruwnik what's rationale on removing this?
I think this code is providing backwards compatibility for links from the old site to go to the question that the link points to. Even though the new site is live now, couldn't the links still be out there?
Of course, maybe supporting this feature isn't worth it or maybe the implementation is causing problems.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, you're right. I thought this was dead code, but of course it's required to support old links

Comment on lines +100 to +103
data.then((val) => {
const question = val as Question
if (question.title) document.title = question.title
})
Copy link
Collaborator

@jrhender jrhender Mar 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ideally this as Question cast would be removed as it breaks type safety and makes it more likely that a bug would be introduced if the return type of the loader is changed. This seems better IMHO:

Suggested change
data.then((val) => {
const question = val as Question
if (question.title) document.title = question.title
})
data.then((val) => {
if ('title' in val && val.title) document.title = val.title
})

If a property is used in the conditional that doesn't help with the narrowing, then there is a TS error
image

If a property is used in the assignment that doesn't exist on the narrowed type, then there is also a TS error
image

@mruwnik mruwnik merged commit dd1e10e into master Mar 27, 2024
1 check passed
@mruwnik mruwnik deleted the sundry-fixes branch March 27, 2024 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants